#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 3e5 + 5;
const int MOD = 998244353;

int n, m;
int head[N];
int ver[N << 1], Next[N << 1], tot;
void add(int u, int v) {
  ++tot;
  ver[tot] = v;
  Next[tot] = head[u];
  head[u] = tot;
}
int f[N][20], dep[N];
void dfs(int u, int fu) {
  f[u][0] = fu;
  for (int i = head[u]; i; i = Next[i]) {
    int v = ver[i];
    if (v == fu) continue;
    dep[v] = dep[u] + 1;
    dfs(v, u);
  }
}
ll sum[55][N];
void init() {
  dfs(1, 0);
  rep(j, 1, 18) rep(i, 1, n) f[i][j] = f[f[i][j - 1]][j - 1];
  rep(i, 1, n) {
    ll x = 1;
    rep(k, 1, 50) {
      x = x * i % MOD;
      sum[k][i] = (sum[k][i - 1] + x) % MOD;
    }
  }
}
int lca(int u, int v) {
  if (dep[u] < dep[v]) swap(u, v);
  int d = dep[u] - dep[v];
  per(j, 18, 0) if (d & (1 << j)) u = f[u][j];
  if (u == v) return u;
  per(j, 18, 0) if (f[u][j] != f[v][j]) u = f[u][j], v = f[v][j];
  return f[u][0];
}
ll fastpow(ll b, ll p) {
  ll res = 1;
  while (p) {
    if (p & 1) res = res * b % MOD;
    b = b * b % MOD;
    p >>= 1;
  }
  return res;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  rep(i, 2, n) {
    int u, v;
    cin >> u >> v;
    add(u, v), add(v, u);
  }
  init();
  cin >> m;
  while (m--) {
    int u, v, k;
    cin >> u >> v >> k;
    int x = lca(u, v);
    ll ans = sum[k][dep[u]] + sum[k][dep[v]] - sum[k][dep[x]] * 2 +
             fastpow(dep[x], k);
    ans %= MOD;
    if (ans < 0) ans += MOD;
    cout << ans << endl;
  }
  return 0;
}